﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace QuanLiSinhVienThucTap
{
    public partial class QuanLyGiangVien : DevComponents.DotNetBar.Metro.MetroForm
    {
        public QuanLyGiangVien()
        {
            InitializeComponent();
        }

        private int maso;
        private void labelX3_Click(object sender, EventArgs e)
        {

        }

        private void superTabControlPanel1_Click(object sender, EventArgs e)
        {

        }

        private void labelX10_Click(object sender, EventArgs e)
        {

        }

        private void dataGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void groupTTGV_Click(object sender, EventArgs e)
        {
            dataGV.Rows.Add();
        }

        private void QuanLyGiangVien_Load(object sender, EventArgs e)
        {
            dataGV.DataSource = XuliLenh.dulieusinhvien("GVHD");
            cbMAkhoa.DataSource = XuliLenh.LocMaKhoa("khoa", "makhoa");
        }

        private void txtnameGV_TextChanged(object sender, EventArgs e)
        {

        }
        private void Loaddatagiangvien()
        {
            dataGV.DataSource = XuliLenh.loaddulieu("GVHD");
        }
        int index = -1;
        private void dataGV_SelectionChanged(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection hangchon = dataGV.SelectedRows;
            cbNamgv.CheckValue = false;
            cbNugv.CheckValue = false;
            int a = -1;
            if (hangchon.Count > 0 && hangchon.Count < 2)
            {
                DataGridViewRow chonhang = hangchon[0];
                txtnameGV.Text = chonhang.Cells["tengv"].Value.ToString().Trim();
                txtMAGV1.Text = chonhang.Cells["magv"].Value.ToString().Trim();
                txtemailGV.Text = chonhang.Cells["email"].Value.ToString().Trim();
                txtDiaChiGV.Text = chonhang.Cells["diachi"].Value.ToString().Trim();
                dtngaysinhGV.Value = DateTime.Parse(chonhang.Cells["ngsinh"].Value.ToString().Trim());
                txtSDTGV.Text = chonhang.Cells["sdt"].Value.ToString().Trim();

                if (chonhang.Cells["phai"].Value.ToString().Trim() == "Nam" | chonhang.Cells["phai"].Value.ToString().Trim() == "nam")
                {
                    cbNamgv.CheckValue = true;
                }
                else
                {
                    cbNugv.CheckValue = true;
                }
             
                for (int i = 0; i < cbMAkhoa.Items.Count; i++)
                {
                    if (cbMAkhoa.Items[i].ToString() == chonhang.Cells["makhoa"].Value.ToString().Trim())
                    {
                        index = i;
                        break;

                    }
                }
                //cbMAkhoa.SelectedIndex = index;
                cbMAkhoa.SelectedItem = cbMAkhoa.Items[index];}
        }
        private
            void labelX12_Click(object sender, EventArgs e)
        {

        }

        private void superTabControlPanel2_Click(object sender, EventArgs e)
        {

        }
        //dung de tim kiem giang vien
        private void bttimGV_Click(object sender, EventArgs e)
        {
            //dataGV.DataSource = XuliLenh.Loctimmakhoa("GVHD", txttimMakhoa.Text.ToString());
            dataGV.DataSource = XuliLenh.loctimmagv("GVHD", txtMAGV.Text.ToString());
            //dataGV.DataSource = XuliLenh.loctimmtenGV("GVHD", txtTenGV.Text.ToString());
        }

        

        private void dtngaysinhGV_ValueChanged(object sender, EventArgs e)
        {

        }

        private void cbNamgv_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void btXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc muốn xóa không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                if (txtMAGV1.Text != "")
                {
                    XuliLenh.xoaGV("GVHD", txtMAGV1.Text);
                    Loaddatagiangvien();                   
                    txtMAGV1.Clear();
                    txtTenGV.Clear();
                    txtSDTGV.Clear();
                    txtDiaChiGV.Clear();
                    txtemailGV.Clear();
                }
                else
                {
                    MessageBox.Show("Bạn chưa nhập mã sách cần xóa!!hãy chọn dòng bạn muốn xóa", "Lỗi");
                    return;
                }
            }
        }

        private void btSua_Click(object sender, EventArgs e)
        {
            if (txtMAGV1.Text != "")
            {
                string ChuoiMaKhoa = "";
                {
                    if (MessageBox.Show("Bạn chắc muốn sửa không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {

                        ChuoiMaKhoa = cbMAkhoa.Items[index].ToString();
                        if (cbNamgv.Checked == true)
                            XuliLenh.sua("GVHD", txtMAGV1.Text, txtnameGV.Text, "Nam", dtngaysinhGV.Value, txtemailGV.Text, txtSDTGV.Text, txtDiaChiGV.Text, ChuoiMaKhoa);
                        else
                        {
                            XuliLenh.sua("GVHD", txtMAGV1.Text, txtnameGV.Text, "Nữ", dtngaysinhGV.Value, txtemailGV.Text, txtSDTGV.Text, txtDiaChiGV.Text, ChuoiMaKhoa);
                        }Loaddatagiangvien();
                    }
                }

                cbMAkhoa.Refresh();}
        }

        private void txtMAGV_TextChanged(object sender, EventArgs e)
        {

        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void cbMAkhoa_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btTHEM_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc muốn thêm chứ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                if (cbNamgv.Checked == true)
                {
                    XuliLenh.themGV("GVHD", txtMAGV1.Text, cbMAkhoa.SelectedValue.ToString(), txtnameGV.Text, "Nam",
                        dtngaysinhGV.Value, txtSDTGV.Text, txtemailGV.Text, txtDiaChiGV.Text);

                }
                else
                {
                    XuliLenh.themGV("GVHD", txtMAGV1.Text, cbMAkhoa.SelectedValue.ToString(), txtnameGV.Text, "Nu",
                        dtngaysinhGV.Value, txtSDTGV.Text, txtemailGV.Text, txtDiaChiGV.Text);

                }
                Loaddatagiangvien();
               
            }
        }

        private void txtMAGV1_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtemailGV_TextChanged(object sender, EventArgs e)
        {

        }
       
    }
}